<template>
  <div class="main"></div>
</template>

<script>
import Vue from 'vue'
import { Dialog } from 'vant'
import { timeFix } from '@/utils/util'
import { mapActions } from 'vuex'
import { ACCESS_TOKEN } from '@/store/mutation-types'
import { Notify } from 'vant';

export default {
  data() {
    return {}
  },
  created() {
    Vue.ls.remove(ACCESS_TOKEN)
  },
  mounted() {
    this.login()
  },
  methods: {
    ...mapActions(['ZwtAppLogin']),
    login() {
      const appToken = this.$route.query.sessionId
      const loginParams = {}
      loginParams.token = appToken
      this.ZwtAppLogin(loginParams)
        .then((res) => {
          console.log(res)
          this.departConfirm(res)
        })
        .catch((err) => {
          this.requestFailed(err)
        })
    },
    departConfirm(res) {
      if (res.success) {
        let multi_depart = res.result.multi_depart
        //0:无部门 1:一个部门 2:多个部门
        if (multi_depart == 0) {
          this.loginSuccess()
        } else {
          this.loginSuccess()
        }
      } else {
        this.requestFailed(res)
        // this.Logout();
      }
    },
    loginSuccess() {
      Vue.ls.set('LOGIN_APP_TYPE', 'ZWT')
      // const isJump = localStorage.getItem('$showGridArrow') === 'true'
      // if (isJump) return
      this.$router.replace({ path: '/' })
      this.$notify({ type: 'success', message: `${timeFix()}，欢迎回来` })
    },
    requestFailed(err) {
      Dialog({ title: '登陆失败', message: '您不是代理商用户，请重试或联系管理员！页面将关闭！' }).then(() => {
        WadeMobile.closeH5()
      })
    },
  },
}
</script>